package no.ntnu.fp.net.co;

public enum MessageType {

	/**
	 * The message types that packages can have. This is used in the packet header	
	 */
		MSG_LOGIN,							//Login to the server
		MSG_GET_ALL_USERS,					//Get all registered users in the database
		MSG_GET_APPOINTMENTS,				//Get appointments
		MSG_GET_PARTICIPANTS,				//Get participents by appointmentID
		MSG_CREATE_APPOINTMENT,				//Create new appointment
		MSG_DELETE_APPOINTMENT,				//Remove existing appointment
		MSG_GET_FREE_MEETING_ROOMS,			//Get all free meeting rooms in the specified time period
		MSG_GET_ALL_MEETING_ROOMS,			//Get a detailed list of all meeting rooms in the database
		MSG_GET_NOTIFICATIONS,				//Gets all notifications associated with the logged in user
		MSG_CREATE_USER,					//Create new user
		MSG_GET_APPOINTMENT_REPLY,			//Gets the replies of all participants in an appointment
		MSG_REMOVE_USER_FROM_APPOINTMENT, 	//Removes a single user from an appointment
		MSG_UPDATE_NOTIFICATION,			//Changes the status of the specified notification
		MSG_INFO_TEXT;				 	  	//Send text message and print to console (debug)

	/**
	 * This function encodes a message to send on the network using this protocol
	 * @param type 		The type of the message to send (used in package header so that 
	 * 					the receiver knows how many arguments to expect)
	 * @param args 		An arbitrary amount of String arguments to package in the message
	 * @return 			The encoded message (example: 5;johan;password;nick)
	 */
	public static String compileMessage( MessageType type, String ... args ) {
		String result = type.name();
		result = result.concat(";");

		//Add all of the optional parameters
		for( String param : args ){
			result = result.concat(param);
			result = result.concat(";");
		}

		//Console.printConsole("Created new message: " + result);

		return result;
	}

}